﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Services;
using ADONETDataServicesExtension.Utils;
using ADONETDataServicesExtension.Providers;

namespace ADONETDataServicesExtension
{
    public class IDataService : FrameworkEncapsulatedType<object>
    {
        internal const string FrameworkTypeName = "System.Data.Services.IDataService";

        public IDataService(object iDataService)
            : base(iDataService)
        {
        }

        public IDataServiceHost Host
        {
            get
            {
                return ReflectionHelper.GetProperty<IDataServiceHost>(FrameworkTypeName, "Host", FrameworkObject);
            }
        }

        public void DisposeDataSource()
        {
            ReflectionHelper.InvokeVoidMethod(FrameworkTypeName, "DisposeDataSource", FrameworkObject);
        }

        public IDataServiceProvider Provider
        {
            get
            {
                return ReflectionHelper.Convert(ReflectionHelper.GetProperty(FrameworkTypeName, "Provider", FrameworkObject), frameworkValue => new IDataServiceProvider(frameworkValue));
            }
        }

        public DataServiceConfiguration Configuration
        {
            get
            {
                return ReflectionHelper.Convert(ReflectionHelper.GetProperty<IDataServiceConfiguration>(FrameworkTypeName, "Configuration", FrameworkObject), frameworkValue => new DataServiceConfiguration(frameworkValue));
            }
        }

        public void InternalApplyingExpansions(IQueryable queryable, ICollection<ExpandSegmentCollection> expandPaths)
        {
            ReflectionHelper.InvokeVoidMethod(FrameworkTypeName, "InternalApplyingExpansions", FrameworkObject, queryable, expandPaths);
        }

        public CachedRequestParams RequestParams
        {
            get
            {
                return ReflectionHelper.Convert(ReflectionHelper.GetProperty(FrameworkTypeName, "RequestParams", FrameworkObject), frameworkValue => new CachedRequestParams(frameworkValue));
            }
        }
    }
}
